<div class="layui-container">
    <div class="layui-row">
        <div class="layui-col-sm12 layui-col-md12 layui-col-lg12">
			<div class="widget-head">
				<div class="widget-title">分销商提现申请</div>
			</div>
			<div class="layui-col-md12 layui-col-xs12 widget-body ">	
				<!-- 工具栏 -->
				<div class="page_toolbar ">
					<form class="layui-form" method="post" action="">
						<input type="hidden" name="s" value="/{$request->pathinfo()}">
						<input type="hidden" name="user_id" value="{$request->get('user_id')}">
						<div class="layui-col-sm12 layui-col-md12">
							<div class="layui">
								<div class="layui-col-md4 layui-col-flex layui-col-one">
									<label class="layui-form-label">审核状态：</label>
									<select class="form-control" name="apply_status" data-layer-selected="{btnSize: 'sm', placeholder: '审核状态'}">
										<option value="-1" {$request->get('apply_status') === '-1' ? 'selected' : ''}>全部</option>
										<option value="10" {$request->get('apply_status') === '10' ? 'selected' : ''}>待审核</option>
										<option value="20" {$request->get('apply_status') === '20' ? 'selected' : ''}>审核通过</option>
										<option value="40" {$request->get('apply_status') === '40' ? 'selected' : ''}>已打款</option>
										<option value="30" {$request->get('apply_status') === '30' ? 'selected' : ''}>驳回</option>
									</select>
								</div>
								<div class="layui-col-md4 layui-col-flex layui-col-one">
									<label class="layui-form-label">体现方式：</label>
									<select class="form-control" name="pay_type" data-layer-selected="{btnSize: 'sm', placeholder: '提现方式'}">
										<option value="-1" {$request->get('pay_type') == '-1' ? 'selected' : ''}>全部</option>
										<option value="20" {$request->get('pay_type') == '20' ? 'selected' : ''}>支付宝</option>
										<option value="30" {$request->get('pay_type') == '30' ? 'selected' : ''}>银行卡</option>
									</select>
								</div>
								<div class="layui-col-md3 layui-col-flex layui-col-one">
									<label class="layui-form-label">关键词：</label>
									<div class="layui-input-inline">
										<input type="text" class="layui-input" name="search" placeholder="请输入姓名/手机号" value="{$request->get('search')}">
									</div>
								</div>
								<div class=" layui-col-md2">
									<button class="layui-btn" lay-submit lay-filter="formDemo">搜索</button>
								</div>
							</div>
						</div>
					</form>
				</div>
				<div class="layui-col-md12" >
					<table width="100%" class="layui-table tpl-table-black">
						<thead>
						<tr>
							<th>用户ID</th>
							<th>微信头像</th>
							<th>微信昵称</th>
							<th>
								<p>姓名</p>
								<p>手机号</p>
							</th>
							<th>提现金额</th>
							<th>提现方式</th>
							<th>提现信息</th>
							<th class="">审核状态</th>
							<th>申请时间</th>
							<th>审核时间</th>
							<th>操作</th>
						</tr>
						</thead>
						<tbody>
						{if !$list->isEmpty()}{foreach $list as $item}
					  
							<tr>
								<td>{$item['user_id']}</td>
								<td>
									<a href="{$item['avatarUrl']}" title="点击查看大图" target="_blank">
										<img src="{$item['avatarUrl']}"
											 width="50" height="50" alt="">
									</a>
								</td>
								<td>
									<p><span>{$item['nickName']}</span></p>
								</td>
								<td>
								   {if (!empty($item['real_name']) or !empty($item['mobile']))}
										<p>{$item['real_name'] ?: '--'}</p>
										<p>{$item['mobile'] ?: '--'}</p>
									{else/}
										<p>--</p>
									{/if}
								</td>
								<td>
									<p><span>{$item['money']}</span></p>
								</td>
								<td>
									<p><span>{$item['pay_type']['text']}</span></p>
								</td>
								<td>
									{if ($item['pay_type']['value'] == 20)}
										<p><span>{$item['alipay_name']}</span></p>
										<p><span>{$item['alipay_account']}</span></p>
									{elseif ($item['pay_type']['value'] == 30) /}
										<p><span>{$item['bank_name']}</span></p>
										<p><span>{$item['bank_account']}</span></p>
										<p><span>{$item['bank_card']}</span></p>
									{else/}
										<p><span>--</span></p>
								   {/if}
								</td>
								<td>
									{if $item['apply_status'] == 10}
										<span class="layer-badge">待审核</span>
									{elseif ($item['apply_status'] == 20)/}
										<span class="layer-badge layer-badge-secondary">审核通过</span>
								   {elseif ($item['apply_status'] == 30)/}
										<p><span class="layer-badge layer-badge-warning">已驳回</span></p>
										<span class="f-12">
											<a class="j-show-reason" href="javascript:void(0);"
											   data-reason="{$item['reject_reason']}">
												查看原因</a>
										</span>
									{elseif ($item['apply_status'] == 40)/}
										<span class="layer-badge layer-badge-success">已打款</span>
									{/if}
								</td>
								<td>{$item['create_time']}</td>
								<td>{$item['audit_time'] ?: '--'}</td>
								<td>
									<div class="tpl-table-black-operation">
									   {if (in_array($item['apply_status'], [10, 20]))}
											<a class="j-audit" data-id="{$item['id']}"
											   href="javascript:void(0);">
												<i class="layer-icon-pencil"></i> 审核
											</a>
											{if ($item['apply_status'] == 20)}
												<a class="j-money tpl-table-black-operation-del"
												   data-id="{$item['id']}" href="javascript:void(0);">确认打款
												</a>
											{/if}
										{/if}
										{if (in_array($item['apply_status'], [30, 40]))}
											<span>---</span>
									   {/if}
									</div>
								</td>
							</tr>
						{/foreach}{else/}
							 <tr>
								<td colspan="12" class="layer-text-center">暂无记录</td>
							</tr>
					   {/if}
						</tbody>
					</table>
					<div class="layui-col-lg12">
						<div class="">{$list->render()|raw} </div>
						<div class="pagination-total">
							<div class="">总记录：{$list->total()}</div>
						</div>
					</div>
				</div>
			</div>
        </div>
    </div>
</div>

<!-- 提现审核 -->
<script id="tpl-dealer-withdraw" type="text/template">
    <div class="layer-padding-top-sm">
        <form class="form-dealer-withdraw layer-form tpl-form-line-form" method="post"
              action="{:url('user/withdraw')}">
            <input type="hidden" name="id" value="{{ id }}">
            <div class="layer-form-group">
                <label class="layui-col-sm3 layer-form-label"> 审核状态： </label>
                <div class="layui-col-sm8">
                    <label class="layui-input-block">
                        <input type="radio" name="withdraw[apply_status]" value="20" data-layer-ucheck
                               checked> 审核通过
                    </label>
                    <label class="layui-input-block">
                        <input type="radio" name="withdraw[apply_status]" value="30" data-layer-ucheck> 驳回
                    </label>
                </div>
            </div>
            <div class="layer-form-group">
                <label class="layui-col-sm3 layer-form-label"> 驳回原因： </label>
                <div class="layui-col-sm8" style="margin-right:10px;">
                    <input type="text" class="tpl-form-input" name="withdraw[reject_reason]" placeholder="仅在驳回时填写"   value="">
                </div>
            </div>
        </form>
    </div>
</script>

<script>
    $(function () {

        /**
         * 审核操作
         */
        $('.j-audit').click(function () {
            var $this = $(this);
            layer.open({
                type: 1
                , title: '提现审核'
                , area: '600px'
                , offset: 'auto'
                , anim: 1
                , closeBtn: 1
                , shade: 0.3
                , btn: ['确定', '取消']
                , content: template('tpl-dealer-withdraw', $this.data())
                , success: function (layero) {
                    // 注册radio组件
                    //layero.find('input[type=radio]').uCheck();
                }
                , yes: function (index, layero) {
                    // 表单提交
                    layero.find('.form-dealer-withdraw').ajaxSubmit({
                        type: 'post',
                        dataType: 'json',
                        success: function (result) {
                            result.code === 1 ? $.show_success(result.msg, result.url)
                                : $.show_error(result.msg);
                        }
                    });
                    layer.close(index);
                }
            });
        });

        /**
         * 显示驳回原因
         */
        $('.j-show-reason').click(function () {
            var $this = $(this);
            layer.alert($this.data('reason'), {title: '驳回原因'});
        });

        /**
         * 确认打款
         */
        $('.j-money').click(function () {
		
            var id = $(this).data('id');
            var url = "{:url('user/withdraw')}";
            layer.confirm('确定已打款吗？', function (index) {
                $.post(url, {id: id}, function (result) {
                    result.code === 1 ? $.show_success(result.msg, result.url)
                        : $.show_error(result.msg);
                });
                layer.close(index);
            });
        });

    });
</script>

